<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets" xmlns="http://www.w3.org/1999/xhtml" xmlns:a4j="http://richfaces.org/a4j" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:st="http://www.whatisjee.com/ssf/tags" xmlns:rich="http://richfaces.org/rich" xmlns:s="http://jboss.com/products/seam/taglib" xmlns:sf="http://www.whatisjee.com/ssf/functions" template="/common/template/#{param['cb'] eq null ? 'header-content' : 'popup'}.xhtml">
	<ui:param name="title" value="#{messages['log.query']}"/>
	<ui:define name="content">
		<div class="container">
			<s:validateAll>
				<h:panelGrid columns="4" styleClass="form" columnClasses="label,input,label,input">
					<st:label for="cFrom" value="#{messages['log.loggedAt']}" />
					<h:panelGroup>
						<rich:calendar id="cFrom" value="#{logsAct.criteria.from}" datePattern="#{messages['cmm.shortDate']}" inputClass="inputtext" weekDayLabelsShort="#{messages['cmm.shortDayLbls']}" />
						<h:outputText value=" - " />						
						<rich:calendar id="cTo" value="#{logsAct.criteria.to}" datePattern="#{messages['cmm.shortDate']}" inputClass="inputtext" weekDayLabelsShort="#{messages['cmm.shortDayLbls']}" />
					</h:panelGroup>
					<st:label for="itName" value="#{messages['log.username']}" />
					<s:decorate>
						<h:inputText id="itName" value="#{logsAct.criteria.username}" styleClass="inputtext width50" />
					</s:decorate>
					<st:label for="itTerminal" value="#{messages['log.terminal']}" />
					<s:decorate>
						<h:inputText id="itTerminal" value="#{logsAct.criteria.terminal}" styleClass="inputtext width50" />
					</s:decorate>
					<st:label for="somSeverity" value="#{messages['log.severity']}" />
					<s:decorate>
						<h:selectOneMenu id="somSeverity" value="#{logsAct.criteria.severity}">
							<s:selectItems var="_type" value="#{$c['LOG_LABELS']}" label="#{_type[0]} - #{messages[_type[1]]}" itemValue="#{_type[0]}" noSelectionLabel="#{messages['cmm.noSelection']}" />
						</h:selectOneMenu>
					</s:decorate>
				</h:panelGrid>
			</s:validateAll>
			<div class="buttons">
				<h:commandButton action="#{logsAct.find}" value="#{messages['cmm.find']}" styleClass="button" />
				<input type="button" value="#{messages['cmm.cancel']}" class="button cancel" onclick="#{param['cb'] eq null ? 'Ssf.cancel()' : 'window.close()'}" />
			</div>
			<rich:dataTable id="dtLogs" value="#{logsAct.data}" var="_log" rows="#{logsAct.data.page.rows}" styleClass="list">
				<rich:column sortBy="#{loggedAt}" styleClass="align-c" headerClass="align-c" selfSorted="true" sortOrder="DESCENDING">
					<f:facet name="header">
						<h:outputText value="#{messages['log.loggedAt']}"/>
					</f:facet>
					<h:outputText value="#{_log.loggedAt}">
						<s:convertDateTime pattern="#{messages['cmm.shortDateTime']}" />
					</h:outputText>
				</rich:column>
				<rich:column sortBy="#{username}" styleClass="align-l" headerClass="align-l">
					<f:facet name="header">
						<h:outputText value="#{messages['log.username']}"/>
					</f:facet>
					<h:outputText value="#{_log.username}" />
				</rich:column>
				<rich:column sortBy="#{terminal}" styleClass="align-c" headerClass="align-c">
					<f:facet name="header">
						<h:outputText value="#{messages['log.terminal']}"/>
					</f:facet>
					<h:outputText value="#{_log.terminal}" />
				</rich:column>
				<rich:column sortBy="#{severity}" styleClass="align-c" headerClass="align-c">
					<f:facet name="header">
						<h:outputText value="#{messages['log.severity']}"/>
					</f:facet>
					<h:outputText value="#{messages[$c['LOG_LABELS'][_log.severity - 1][1]]}" />
				</rich:column>
				<rich:column sortBy="#{summary}" styleClass="align-l" headerClass="align-l">
					<f:facet name="header">
						<h:outputText value="#{messages['log.summary']}"/>
					</f:facet>
					<h:outputText value="#{sf:getLogSummary(_log)}" />
				</rich:column>
				<rich:column styleClass="align-c" headerClass="align-c">
					<f:facet name="header">
						<h:outputText value="#{messages['log.detail']}"/>
					</f:facet>
					<a4j:commandLink action="#{logsAct.showDetail}" reRender="itDetail" oncomplete="Richfaces.showModalPanel('mpDetail')" rendered="#{not empty _log.detail}" styleClass="icon">
						<h:graphicImage value="/common/image/view.gif" alt="#{messages['cmm.remove']}" />
					</a4j:commandLink>
				</rich:column>
			</rich:dataTable>
			<rich:datascroller for="dtLogs" />
			<rich:modalPanel id="mpDetail" height="480" width="640">
				<f:facet name="header">
					<h:outputText value="#{messages['log.detail']}" />
				</f:facet>
				<f:facet name="controls">
					<h:graphicImage value="/common/image/close.gif" style="cursor:pointer" onclick="Richfaces.hideModalPanel('mpDetail')" />
				</f:facet>
				<h:inputTextarea id="itDetail" value="#{logsAct.detail}" style="height:100%;width:100%;height:430px\9" />
			</rich:modalPanel>
		</div>
	</ui:define>
</ui:composition>
